import { getUser } from '@/utils/cookie';
import { whiteList } from '@/utils/setting';

export default function ({
  route,
  req,
  res,
  store,
  redirect
}) {
  const isClient = process.client;
  // 在客户端判读是否需要登陆
  if (isClient) {
    // 只有当前环境在客户端才会执行
    const USER = getUser();
    if (!USER) {
      // 路由白名单
      // if (!whiteList.includes(route.name)) {
      //   store.dispatch('user/toggleModal', {
      //     login: true
      //   })
      //   return redirect('/')
      // }
    } else {
      !store.state.user.authUser && store.dispatch('user/userInfo', JSON.parse(USER))
    }
    // console.log(getToken());
  }
}
